package com.wiegand.util {
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	/**
	 * @author rzimmermann
	 */
	public class CropPic {
		public static function get_opaqueRect( _do : DisplayObject ) : Rectangle {  
			var bmd : BitmapData = new BitmapData(_do.width, _do.height, true, 0x00FFFFFF);  
			bmd.draw(_do);  
			return Rectangle( bmd.getColorBoundsRect( 0xFF000000, 0x00000000, false ) );  
		}  

		public static function get_opaqueBMD( _do : DisplayObject ) : BitmapData {  
			var cropRect : Rectangle = get_opaqueRect(_do) as Rectangle;  
			var preBMD : BitmapData = new BitmapData(_do.width, _do.height, true, 0x00FFFFFF);  
			var postBMD : BitmapData = new BitmapData(cropRect.width, cropRect.height, true, 0xFFFFFFFF);  
			preBMD.draw(_do);  
			postBMD.copyPixels(preBMD, cropRect, new Point(0, 0));  
			preBMD.dispose();  
			return postBMD;  
		}		
	}
}
